<?php

namespace app\api\controller\v1;


use addons\third\model\Third;
use app\admin\controller\Zlog;
use app\common\controller\Api;
use addons\adszone\library\Adszone;
use app\common\logic\CourseLogic;
use app\common\logic\LearnLogic;

/**
 * 首页接口
 */
class Index extends Api
{
    protected $noNeedLogin = ['index'];
    protected $noNeedRight = '*';

    /*
     * 首页接口
     * */
    public function index() {
        //获取首页轮播图
        $pic = new Adszone();
        $list = $pic->getAdsByMark('wxapp_frist_banner',ORG_CATE_ID);
        //获取首页中间图
        $mid_list = $pic->getAdsByMark('wxapp_middle_banner',ORG_CATE_ID);
        //获取热门课程
        $hot = (new LearnLogic())->getHotCourse(4);
        $learnLogic = new LearnLogic();
        //首页 专题分类
        $specials = $learnLogic->getLearnCateSpecial();
        foreach ($specials as $k => $v) {
            $data = $learnLogic->getLearnCateSpecialCourse($v['id'], 4);
            if(!empty($data)){
                $specials[$k]['courses'] = $data;
            }
        }
        $third= Third::get(UID);
        if(isset($third['u_id']) && $third['u_id'] > 0){
            $is_bind = true;
        }else{
            $is_bind = false;
        }
        $this->success('首页数据',[
            'pic' => $list,
            'mid_pic' => $mid_list,
            'hot' => $hot,
            'specials' => $specials,
            'is_bind' => $is_bind
        ]);
    }


}
